import React, { Component } from "react";

class Counter extends Component {
  // 初始化状态
  constructor(props) {
    super(props);
    // 设置初始状态
    this.state = {
      count: 0,
      count1: 0,
    };
    console.log("count1", this.state.count1);
  }

  // 增加计数的方法
  incrementCount = () => {
    this.setState({ count: this.state.count + 1 }, () => {
      console.log("🚀 ~ Counter ~ this.setState ~ count:", this.state.count);
    }); // 更新状态
  };

  // 减少计数的方法
  decrementCount = () => {
    this.setState((prevState) => ({ count: prevState.count - 1 })); // 使用函数更新状态
  };

  //   setInterval(() => {

  //   }, 1000);

  render() {
    return (
      <div>
        <h1>Count: {this.state.count}</h1>
        <button onClick={this.incrementCount}>Increment</button>
        <button onClick={this.decrementCount}>Decrement</button>
      </div>
    );
  }
}

export default Counter;
